n = int(input())
board = [[-1 for _ in range(n)] for _ in range(n)]
inf = float('inf')


def check_win(player, k=3):
    """
    检查 player 是否在 board 中形成连续 k 子
    :param player: 玩家标识 (例如 0 或 1)
    :param k: 连子数
    :return: True 如果获胜，否则 False
    """
    rows, cols = len(board), len(board[0])

    # 方向向量：右、下、右下、左下
    directions = [(0, 1), (1, 0), (1, 1), (1, -1)]

    for i in range(rows):
        for j in range(cols):
            if board[i][j] != player:
                continue
            # 从 (i,j) 出发检测 4 个方向
            for dx, dy in directions:
                count = 0
                x, y = i, j
                while 0 <= x < rows and 0 <= y < cols and board[x][y] == player:
                    count += 1
                    if count == k:
                        return True
                    x += dx
                    y += dy
    return False


def dfs(player):
    ans = []
    flag = True
    for i in range(n):
        for j in range(n):
            if board[i][j] == -1:
                flag = False
                board[i][j] = player
                if check_win(player):
                    board[i][j] = -1
                    return (1 if player == 0 else -1), (i, j)
                res, _ = dfs(1 ^ player)
                ans.append((res, (i, j)))
                board[i][j] = -1

    if flag:
        return 0, tuple()
    if player == 0:  # 先手，最大化
        return max(ans, key=lambda x: x[0])
    else:  # 后手，最小化
        return min(ans, key=lambda x: x[0])


while True:
    print("请输入xy")
    x, y = map(int, input().split())
    board[x][y] = 1
    v, p = dfs(0)
    print(f"电脑计算得到最佳位置为{p} 价值为{v}")
    board[p[0]][p[1]] = 0
    for i in range(n):
        for j in range(n):
            print(board[i][j], end=' ')
        print()
    if check_win(1):
        print("玩家获胜")
        break
    elif check_win(0):
        print("电脑获胜")
        break
